package com.example;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import io.reactivex.Observable;
import io.reactivex.functions.BiFunction;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function3;

public class Example_V2 {

    public static void main(String[] args){
//        testZip();
        testMergeWith();
    }

    private static void testMergeWith(){
        Observable<String> observable1 = Observable.just("zhu", "ying", "ming", "is", "good", "man");
        Observable<String> observable2 = Observable.just("5", "6", "7", "8");
        observable1.mergeWith(observable2).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("============ " + s);
            }
        });
    }

    private static void testZip(){
        Observable<String> observable1 = Observable.just("zhu", "ying", "ming", "is", "good", "man");
        Observable<Integer> observable2 = Observable.just(5, 6, 7, 8);
        Observable<Integer> observable3 = Observable.just(5, 6, 7, 8);
        Observable.zip(observable1, observable2, new BiFunction<String, Integer, String>() {
            @Override
            public String apply(String s, Integer integer) throws Exception {
                return s + " == " + integer + " , " ;
            }
        }).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("s == " + s);
            }
        });

    }

    private static void testZipWith(){
        Observable<String> observable1 = Observable.just("zhu", "ying", "ming", "is", "good", "man");
        Observable<String> observable2 = Observable.just("5", "6", "7", "8");
        observable1.concatWith(observable2).subscribe(new Consumer<String>() {
            @Override
            public void accept(String s) throws Exception {
                System.out.println("============ " + s);
            }
        });
//        observable1.zipWith(observable2, new BiFunction<String, Integer, String>() {
//            @Override
//            public String apply(String s, Integer integer) throws Exception {
//                return s + " = ? " + integer;
//            }
//        }).subscribe(new Consumer<String>() {
//            @Override
//            public void accept(String s) throws Exception {
//                System.out.println("============ " + s);
//            }
//        });
    }
}
